package kr.co.hk;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class DaumMaps extends Activity {
	  private static final String LOG_TAG = "WebViewDemo";

	    private WebView mWebView;

	    private Handler mHandler = new Handler();

	    @Override
	    public void onCreate(Bundle icicle) {
	        super.onCreate(icicle);
	        setContentView(R.layout.daum_webview);
	        mWebView = (WebView) findViewById(R.id.webview);

	        WebSettings webSettings = mWebView.getSettings();
	        webSettings.setSavePassword(false);
	        webSettings.setSaveFormData(false);
	        webSettings.setJavaScriptEnabled(true);
	        webSettings.setSupportZoom(true);

	        mWebView.setWebChromeClient(new MyWebChromeClient());

	        mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");

	        mWebView.loadUrl("file:///android_asset/DaumMaps.html");
	        
	        Bundle extra = getIntent().getExtras();
	        if(extra != null){
	        	String str = extra.getString("addr");
	        	Log.v("addr",str);
	        }
	    }

	    final class DemoJavaScriptInterface {

	        DemoJavaScriptInterface() {
	        }

	        /**
	         * This is not called on the UI thread. Post a runnable to invoke
	         * loadUrl on the UI thread.
	         */
	        public void clickOnAndroid() {
	            mHandler.post(new Runnable() {
	                public void run() {
	                	
	                	Log.v("naverwebview","naverwebview");
	                    mWebView.loadUrl("javascript:init()");
	                }
	            });

	        }
	    }

	    /**
	     * Provides a hook for calling "alert" from javascript. Useful for
	     * debugging your javascript.
	     */
	    final class MyWebChromeClient extends WebChromeClient {
	        @Override
	        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
	            Log.d(LOG_TAG, message);
	            result.confirm();
	            return true;
	        }
	    }
	}
//	@Override
   /* public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Uri uri = Uri.parse("http://www.example.com");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
        
        
        WebView webview = new WebView(this);
        setContentView(webview);
        
        StringBuffer summary = new StringBuffer(); 
        	
        summary.append("<!DOCTYPE html> \n")
        		.append("<html> \n")
        		.append("<head> \n")
//        		.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'> \n")
        		.append("<meta name='viewport' content='user-scalable=no, initial-scale=1.0, " +
        				"maximum-scale=1.0, minimum-scale=1.0, width=device-width, target-densityDpi=device-dpi'>")
//        		.append("<title>Daum ���� API v3 ����: ����� �⺻ ���� �ø���</title>")
//        		.append("<style type='text/css'>html, body, #map {margin: 0; padding: 0; width: 100%; height: 100%}</style>")
        		.append("<script type='text/javascript' " +
        				"src='http://apis.daum.net/maps/maps3.js?apikey=DAUM_MAPS_DEMO_APIKEY' ></script> ")
        		.append("<script type='text/javascript'>")
        		.append("var map;")
        		.append("function init() {")
        		.append("map = new daum.maps.Map(document.getElementById('map'), {")
        		.append("center: new daum.maps.LatLng(37.537123, 127.005523)")
        		.append("});")
        		.append("var marker = new daum.maps.Marker({")
        		.append("position: new daum.maps.LatLng(37.537123, 127.005523)")
        		.append("});")
        		.append("marker.setMap(map);")
        		.append("}')")
        		.append("</script> ")
        		.append("</head> ")
//        		.append("<body onload='init()'>")
//        		.append("<div id='map'></div>")
//        		.append("</body> ')")
//        		.append("<meta http-equiv='Content-Type' content='text/html;> \n")
//        		.append("<meta name='viewport' content='user-scalable=no, initial-scale=1.0, " +
//        				"maximum-scale=1.0, minimum-scale=1.0, width=device-width, target-densityDpi=device-dpi'>")
//        		.append("<title>Daum ���� API v3 ����: ����� �⺻ ���� �ø���</title>")
//        		.append("<script type=\"text/javascript\" " +
//        				"src\"http://apis.daum.net/maps/maps3.js?apikey=DAUM_MAPS_DEMO_APIKEY\" ></script> ")
        		.append("<body>����")
        		
        		.append("</body>")
        		.append("</html> ")
        		.append("");
        		
        webview.loadData(summary.toString(), "text/html", "EUC-KR");
        webview.loadUrl("javascript:init()");
        
    }
	
	*/
	
